package com.yeyks.app.controller.base.consumer;

import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.consumer.dal.domain.UserInfo;
import com.yeyks.consumer.dto.SignInDTO;
import com.yeyks.consumer.service.SignInService;
import com.yeyks.consumer.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author fuchangshuai
 * @date 2019/4/24 0024
 */
@Api(tags = "签到接口", description = "签到")
@Slf4j
@RestController
@RequestMapping(value = "/app/sign")
public class SignInController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private SignInService signInService;

    /**
     * 用户签到
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "用户签到", notes = "用户签到(返回签到数量)")
    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
    @PostMapping(value = "/add")
    public AjaxResponseBody<Map<String, Integer>> sign(@RequestParam(name = "token") String token) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        return AjaxResponseBody.success(signInService.signIn(userInfo.getId()));
    }

    /**
     * 获取用户签到信息
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "获取用户签到信息", response = SignInDTO.class)
    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
    @PostMapping(value = "/info")
    public AjaxResponseBody<SignInDTO> isSign(@RequestParam(name = "token") String token) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        SignInDTO signInDTO = signInService.info(userInfo.getId());
        return AjaxResponseBody.success(signInDTO);
    }
}
